<include file="Public/header" title="编辑案例" />
<div id="page-wrapper">
    <form method="post" action="{:U('demos/update')}" enctype="multipart/form-data">
        <input type="hidden" name="demos_id" value="{$info.id}">
        <div class="form-group">
            <label for="post-title">案例标题</label>
            <input type="text" name="title" class="form-control" id="post-title" value="{$info.title}" placeholder="输入案例标题">
        </div>
        <div class="form-group">
            <label for="post-title">设计者</label>
            <input type="text" name="designer" class="form-control" id="post-title" value="{$info.title}" placeholder="输入设计者">
        </div>
        <div class="form-group">
            <label for="post-title">设计时间</label>
            <input type="text" name="design_time" class="form-control" value="{$info.title}" id="post-title" placeholder="输入设计时间">
        </div>
        <div class="form-group">
            <label for="cc">上传主图</label>
            <img id="preview" style="width:40%;height:auto" src="{:C('DEMOS_PATH')}{$info['image']}" />
            <br />
            <input type="file" name="image" onchange="imgPreview(this)" />
        </div>
        <div class="form-group">
            <label>案例类型</label>

            <foreach name="category" item="vv">
                <label class="radio-inline">
                    <input type="radio" name="type" id="type" value="{$vv.id}" <if condition="$info[type] eq $vv[id]">checked="checked"</if>>{$vv.zh_name} | {$vv.en_name}
                </label>
            </foreach>
        </div>

        <div class="form-group">
            <label for="post-content">案例内容</label>
            <script id="post-content" name="content" type="text/plain">{$info.content|htmlspecialchars_decode}</script>
        </div>

        <button type="submit" class="btn btn-primary">提交</button>
        <a href="{:U('demos/index')}" class="btn btn-default">返回列表</a>
    </form>
</div>
<!-- 配置文件 -->
<script type="text/javascript" src="__PUBLIC__/ueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="__PUBLIC__/ueditor/ueditor.all.js"></script>
<!-- 实例化编辑器 -->
<script type="text/javascript">
    var ue = UE.getEditor('post-content',{
        toolbars: [
            ['fullscreen', 'source', 'undo', 'redo','bold', 'italic', 'underline','fontborder', 'strikethrough', '|','simpleupload', 'insertimage','attachment','emotion','link','unlink', '|', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote','searchreplace', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc'],
            ['inserttable','insertrow', 'insertcol','mergeright', 'mergedown','deleterow', 'deletecol','splittorows','splittocols', 'splittocells','deletecaption','inserttitle', 'mergecells', 'deletetable','insertparagraphbeforetable', 'paragraph','fontsize','fontfamily']
        ],
        initialFrameHeight:500,
        zIndex:100
    });
</script>
<script type="text/javascript">
    function imgPreview(fileDom){
        //判断是否支持FileReader
        if (window.FileReader) {
            var reader = new FileReader();
        } else {
            alert("您的设备不支持图片预览功能，如需该功能请升级您的设备！");
        }

        //获取文件
        var file = fileDom.files[0];
        var imageType = /^image\//;
        //是否是图片
        if (!imageType.test(file.type)) {
            alert("请选择图片！");
            return;
        }
        //读取完成
        reader.onload = function(e) {
            //获取图片dom
            var img = document.getElementById("preview");
            //图片路径设置为读取的图片
            img.src = e.target.result;
        };
        reader.readAsDataURL(file);
    }
    function upload() {
        var xhr = new XMLHttpRequest();
        var progress = document.getElementById("progress")
        progress.style.display = "block";

        xhr.upload.addEventListener("progress", function(e) {
            if (e.lengthComputable) {
                var percentage = Math.round((e.loaded * 100) / e.total);
                progress.value = percentage;
            }
        }, false);

        xhr.upload.addEventListener("load", function(e){
            console.log("上传完毕...")
        }, false);

        xhr.open("POST", "upload");
        xhr.overrideMimeType('text/plain; charset=x-user-defined-binary');
        xhr.onreadystatechange = function() {
            if (xhr.readyState == 4 && xhr.status == 200) {
                alert(xhr.responseText); // handle response.
                progress.style.display = "none";
                progress.value = 0;
            }
        };
        var file = document.getElementById("imgFile");
        var fd = new FormData();
        fd.append(file.files[0].name, file.files[0]);
        xhr.send(fd);
    }
</script>
<include file="Public/footer" />